﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Weibo.Data;
using System.Data.Common;
using System.Data;
using Weibo.Entity;
using Weibo.Common;
using System.Data.SqlClient;

namespace Weibo.Data.SqlServer
{
    public partial class DataProvider : IDataProvider  
    {
        public DataTable GetDtByPager(string tableName, string fileds, int pageIndex, int pageSize, string where, string orderby, string sPkey, ref int rowCount)
        {

            DbParameter[] parms =
            {
                DbHelper.MakeInParam("@sField",(DbType)SqlDbType.NVarChar,80,fileds),
                DbHelper.MakeInParam("@sTable",(DbType)SqlDbType.NVarChar,40,tableName),
                DbHelper.MakeInParam("@sWhere",(DbType)SqlDbType.NVarChar,400,where),
                DbHelper.MakeInParam("@sOrderby",(DbType)SqlDbType.NVarChar,40,orderby),
                DbHelper.MakeInParam("@sPkey",(DbType)SqlDbType.NVarChar,10,sPkey),
				DbHelper.MakeInParam("@iPageIndex",(DbType)SqlDbType.Int,4,pageIndex),
                DbHelper.MakeInParam("@iPageSize",(DbType)SqlDbType.Int,4,pageSize),
                DbHelper.MakeOutParam("@iRecordCount",(DbType)SqlDbType.Int,4),
            };

            DataTable dt = DbHelper.ExecuteDataset(CommandType.StoredProcedure, "MyPage", parms).Tables[0];
            rowCount = TypeConverter.ObjectToInt(parms[7].Value);
            return dt;
        }

       

        public DataTable GetCommonDataTable(string tableName, string fileds, string sort, string searchWhere)
        {
            return GetTableByQuery(tableName, searchWhere,fileds,sort,"desc");
        }
    }
}
